package com.bcnapps.DemoGame;

import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class Intro extends Activity {
    
	Thread logoTimer;
	boolean stopped;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        //canvia el control dels botons de volum a media
		this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
		
		//variables globals
		GV.Screen.metrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(GV.Screen.metrics);
		
		//animacio engranatges
		ImageView rodagran = (ImageView)findViewById(R.id.roda_gran);
		rodagran.startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_gran));
		ImageView rodapetita = (ImageView)findViewById(R.id.roda_petita);
		rodapetita.startAnimation(AnimationUtils.loadAnimation(this, R.anim.rotate_petita));
		
		stopped = false;
		logoTimer = new Thread(){
			public void run(){
				try{
					sleep(2000);
					if(!stopped) {
						Intent i = new Intent("com.bcnapps.DemoGame.MAINPAGE");
						startActivity(i);
					}
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				finally{
					finish();
				}
			}
		};
		logoTimer.start();
	}

	@Override
	protected void onStop() {
		super.onStop();
		stopped = true;
		//fer join del thread en el cas de que no estigues dormint
	}
	
	@Override
	public void onBackPressed() {
		finish();
		//activity transition animation
		super.onBackPressed();
	}
}